﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Net;

namespace DecisionTree
{
    static class DBWriter
    {
        public static void WriteDB(byte[][] db, string path)
        {
            using (BinaryWriter b = new BinaryWriter(File.Open(path, FileMode.Create)))
            {
                int magicNumber = 0;
                int numItems = db.Length;
                int numRows = 49;
                int numCols = 16;

                b.Write(IPAddress.NetworkToHostOrder(magicNumber));
                b.Write(IPAddress.NetworkToHostOrder(numItems));
                b.Write(IPAddress.NetworkToHostOrder(numRows));
                b.Write(IPAddress.NetworkToHostOrder(numCols));

                for (int i = 0; i < db.Length; i++)
                    for (int j = 0; j < db[i].Length; j++)
                        b.Write(db[i][j]);
            }
        }

        public static void WriteLabels(byte[] labels, string path)
        {
            using (BinaryWriter b = new BinaryWriter(File.Open(path, FileMode.Create)))
            {
                int magicNumber = 0;
                int numItems = labels.Length;

                b.Write(IPAddress.NetworkToHostOrder(magicNumber));
                b.Write(IPAddress.NetworkToHostOrder(numItems));

                for (int i = 0; i < labels.Length; i++)
                    b.Write(labels[i]);
            }
        }
    }
}
